package com.tuishan.myapplication;

import androidx.fragment.app.FragmentActivity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

import com.chaychan.library.BottomBarItem;
import com.chaychan.library.BottomBarLayout;
import com.jaeger.library.StatusBarUtil;
import com.tuishan.myapplication.Views.Fragment.Fragment_Add;
import com.tuishan.myapplication.Views.Fragment.Fragment_Home;
import com.tuishan.myapplication.Views.Fragment.Fragment_Order;
import com.tuishan.myapplication.Views.Fragment.Fragment_User;
import com.tuishan.myapplication.Views.Fragment.Fragment_Wallet;

public class MainActivity extends FragmentActivity {
    BottomBarLayout bottomBarLayout;
    private  MainActivity mainActivity;
    private Fragment_User mUser;
    private Fragment_Add mAdd;
    private Fragment_Home mHome;
    private Fragment_Order mOrder;
    private Fragment_Wallet mWallet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mainActivity=this;
        StatusBarUtil.setColor(mainActivity,getResources().getColor(R.color.backgroundColor),0);
        init();
        initFragment();
    }

    private void initFragment() {
        mAdd=new Fragment_Add();
        mUser=new Fragment_User();
        mHome=new Fragment_Home();
        mOrder=new Fragment_Order();
        mWallet=new Fragment_Wallet();
        FragmentManager fm=getFragmentManager();
        FragmentTransaction tx=fm.beginTransaction();
        tx.add(R.id.home_frame,mHome,"mHome");
        tx.commit();
    }

    private void init() {
        bottomBarLayout=findViewById(R.id.bbl);
        bottomBarLayout.setOnItemSelectedListener(new BottomBarLayout.OnItemSelectedListener() {
            @Override
            public void onItemSelected(BottomBarItem bottomBarItem, int i, int i1) {
                FragmentManager fm=getFragmentManager();
                FragmentTransaction tx=fm.beginTransaction();
                if (i1==0){
                    tx.replace(R.id.home_frame,mHome,"mHome");
                    tx.commit();
                    StatusBarUtil.setColor(mainActivity,getResources().getColor(R.color.backgroundColor),0);
                }
                if (i1==1){
                    tx.replace(R.id.home_frame,mWallet,"mWallet");
                    tx.commit();
                    StatusBarUtil.setColor(mainActivity,getResources().getColor(R.color.backgroundColor),0);
                }
                if (i1 == 2) {
                    tx.replace(R.id.home_frame,mAdd,"mAdd");
                    tx.commit();
                    StatusBarUtil.setColor(mainActivity,getResources().getColor(R.color.backgroundColor),0);
                }
                if (i1 == 3) {
                    tx.replace(R.id.home_frame,mOrder,"mOrder");
                    tx.commit();
                    StatusBarUtil.setColor(mainActivity,getResources().getColor(R.color.backgroundColor),0);
                }

                if (i1==4){
                    tx.replace(R.id.home_frame,mUser,"User");
                    tx.commit();
                    StatusBarUtil.setColor(mainActivity,getResources().getColor(R.color.homebackgroundColor),0);
                }
            }
        });
    }
}
